package com.singerw.utils;

import java.util.UUID;

/**
 * @version V1.0
 * @Package com.singerw.utils
 * @auhter 张欣
 * @date 2021/1/4-8:07 PMw
 */
public class OSSUtils {

    /**
     * 删除文件名前缀,保留文件名
     * @param path
     * @return
     */
    public static String removePrefix(String path) {
        if (path.lastIndexOf(".") != -1){
            return path.substring(path.lastIndexOf("/") +1);
        }else{
            String temp = path.substring(0,path.length() -1);
            return path.substring(temp.lastIndexOf("/") +1);
        }
    }


    public static String getDirName(String path){
        String t = removePrefix(path);
        return t.substring(0,t.length() - 1);

    }
    /**
     * 删除 'user_space/用户ID/' 开头
     * @param path
     * @return
     */
    public static String removeBasePath(String path){
        String temp = path.substring(path.indexOf("/") + 1, path.length());
        return temp.substring(temp.indexOf("/") + 1);

    }

    /**
     * 根据第一个参数的长度去剪切第二个参数
     * @param casual
     * @param path
     * @return
     */
    public static String removeCasualPath(String casual,String path){
        return path.substring(casual.length());
    }

    public static String removeName(String path){
        if(path.indexOf(".") != -1){
            return path.substring(0,path.lastIndexOf("/"));
        }
        return path.substring(0,path.substring(0,path.length() - 2).lastIndexOf("/") + 1);

    }

    public static String removeHead(String path){
       return path.substring( path.indexOf("/") + 1,path.length());
    }
    public static String setDirPermission(String path){
        return path.substring(0, path.length() - 1) + ":PUBLIC/";

    }

    public static String uuid(){
       return UUID.randomUUID().toString().replaceAll("-", "");
    }
    public static void main(String[] args) {
        System.out.println(setDirPermission("asas/"));
    }

}
